<template>
	<view>
		<dsl-navbar title="出行人" bgTopImg="white" isBack=""></dsl-navbar>
		<view class="crowic pt20" style="padding-bottom: 420rpx;">
			<view class=" position-re">
				<view v-if="addressList &&addressList.length !=0">
					<view class=" box crowjb mb20" v-for="(item,index) in addressList" :key='index'
						@click="addresOrder(item)">
						<view class="rowjbic">
							<view class="rowic">
								<view class="fs28 c000">{{item.realName}}</view>
								<view class="benren ml20 round" style="color: #2ED7C0;">本人</view>
							</view>
							<view class="rowic" @click.stop="addressMen(item)">
								<image style="width: 30rpx;height: 30rpx;" src="/static/img/bianji.png" mode=""></image>
								<view class="fs22 c999 ml20">编辑</view>
								<view class="fs22 text-red ml20" @click.stop="deleteAddress(item)">删除</view>
							</view>
						</view>
						<view class="fs22 c666">{{item.contactNumber}}</view>
					</view>
				</view>
				<view v-else>
					<moreLoading></moreLoading>
				</view>
				<view class="rowjc">
					<view @click="goInfoPage" class="add">添加出行人</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		get_travelMemberList,
		post_removeTravelMember
	} from '../../common/path.js'
	export default {
		data() {
			return {
				addressList: [],
				isAddress: false, //是否是下单页面进入选择
			}
		},
		onLoad(option) {
			if (option.type) {
				this.isAddress = true
				console.log('[选择进入]', true);
			} else {
				this.isAddress = false
				// contart
				uni.removeStorage({  key: 'address', });
			}
		},
		onShow() {
			this.get_travelMemberList() //地址列表
		},
		methods: {
			//删除地址
			deleteAddress(item) {
				let self  = this
				uni.showActionSheet({
					itemList: ['删除地址'],
					success: function(res) {
						if (res.tapIndex == 0) {
							self.deleteAddressApi(item)
						} else {
							
						}
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			//删除地址
			deleteAddressApi(item){
				let data = {
					id:item.id
				}
				this.Http.POST(post_removeTravelMember,data)
				.then((res)=>{
					if(res.code ==0){
						this.get_travelMemberList()
						this.$tools.showToast2('删除成功')
					}else{
						this.$tools.showToast(res.msg)
					}
				})
			},


			goInfoPage() { //出行人详情
				uni.navigateTo({
					url: "setting"
				})
			},
			//地址选择
			addresOrder(item) {
				if (this.isAddress) {
					// let array =[]
					// let list = uni.getStorageSync('address')
					// if(list){
						
					// }
					
					// array.push(item)
					

					uni.setStorageSync('address', item)
					
					
					
					uni.navigateBack({
						delta: 1
					})
				} else {
					let data = JSON.stringify(item)
					uni.navigateTo({
						url: 'setting?data=' + data
					})
				}
			},

			//获取出行人列表接口
			get_travelMemberList() {
				let data = {
					userId: uni.getStorageSync('userInfo').id
				}
				this.Http.POST(get_travelMemberList, data)
					.then((res) => {
						console.log('[地址列表]', res);
						if (res.code == 0) {
							this.addressList = res.data
						}
					})
			},
			//出行
			addressMen(item) {
				let data = JSON.stringify(item)
				uni.navigateTo({
					url: 'setting?data=' + data
				})
			}
		}
	}
</script>

<style>
	page {
		background: #F6F6F6;
	}

	.box {
		background-color: #FFFFFF;
		width: 710rpx;
		height: 130rpx;
		padding: 20rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
	}

	.benren {
		padding: 0rpx 10rpx;
		height: 30rpx;
		line-height: 30rpx;
		background-color: rgba(41, 234, 196, 0.2);
		font-size: 24rpx;
		color: rgba(41, 234, 196);
		border-radius: 10rpx;
	}

	.add {
		width: 500rpx;
		height: 80rpx;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 80rpx;
		text-align: center;
		background-color: #29EAC4;
		border-radius: 36rpx;
		position: fixed;
		bottom: 100rpx;
		left: 0;
		right: 0;
		margin: 0 auto;

	}
</style>
